package com.yidu.qianfeng.service.impl;

import com.yidu.qianfeng.common.bean.finance.FinanceCondition;
import com.yidu.qianfeng.common.bean.finance.Income;
import com.yidu.qianfeng.common.util.JsonMsgUtil;
import com.yidu.qianfeng.common.util.LayuiJsonWrap;
import com.yidu.qianfeng.mapper.IncomeMapper;
import com.yidu.qianfeng.service.IncomeServiceInter;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("incomeServiceImpl")
public class IncomeServiceImpl implements IncomeServiceInter {
    @Resource(name = "incomeMapper")
    private IncomeMapper incomeMapper;

    @Override
    public List<Income> selectAllIncome(int page , int limit) {
        List<Income> incomes = incomeMapper.selectAllIncome(page, limit);
        return incomes;
    }

    @Override
    public String insertIncome(Income income) {
        int insert = incomeMapper.insert(income);
        return JsonMsgUtil.createJsonMessage(insert, "新增成功", "新增失败");
    }

    @Override
    public int selectIncomeCount() {
        return incomeMapper.selectIncomeCount();
    }

    @Override
    public LayuiJsonWrap selectIncomeByCondition(FinanceCondition condition) {
        condition.setOffset((condition.getPage()-1)*condition.getCount());
        condition.setFinanceVoucherNum("%"+condition.getFinanceVoucherNum()+"%");
        return new LayuiJsonWrap(condition.getCount(),incomeMapper.selectIncomeByCondition(condition));
    }

    @Override
    public String selectSubNameById(String empSubstId) {
        return incomeMapper.selectSubNameById(empSubstId);
    }

}
